var app = getApp();

Page({
  data: {
    fid:0,
    loadingBoo: !0,
    moreBoo: !0,
    categories: [{
        id: 1,
        name: '维生素'
      },
      {
        id: 2,
        name: '维生素'
      },
      {
        id: 3,
        name: '维生素'
      },
      {
        id: 4,
        name: '维生素'
      }
    ],
    proList: [],
    hide: true,
    index: '',
    filtant: ['综合', '最新上架', '价格最低', '价格最高', '评价最多'],
    arry: '0',
    serchName:'',
    serchList:[]
  },
  serchShop:function(e){
    console.log(e.detail.value)
    var name=e.detail.value
    var list=this.data.proList
    var serchList=[]
    for(var i=0;i<list.length;i++){
      if(list[i].sname.indexOf(name)!=-1){
        serchList.push(list[i])
      }
    }
    this.setData({
      serchName:name,
      serchList:serchList
    })
  },
  //筛选下拉框
  filtes: function(e) {
    if (e.currentTarget.dataset.index == 0) {
      if (this.data.hide == true) {
        this.setData({
          hide: false,
          index: 0
        })
      } else if (this.data.hide == false) {
        this.setData({
          hide: true
        })
      }
    } else if (e.currentTarget.dataset.index == 1) {
      this.setData({
        index: 1,
        hide: true
      })
    }
  },
  choseitem: function(e) {
    this.setData({
      hide: true,
      arry: e.currentTarget.dataset.index
    })
  },
  tapFun: function(t) {
    var that = this;
    var fid = t.target.dataset.fid
    app.util.request({
      'url': 'entry/wxapp/allfenlgoods',
      data: {
        fid: fid
      },
      success: function(res) {
        console.log(res)
        that.setData({
          proList: res.data.flgoods,
          categories: res.data.fenli,
        })
      }
    })
  },
  shopdetail: function(e) {
    var that = this
    console.log(that.data.type)
    if (that.data.type == 1) {
      console.log(that.data.type)
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2];
      prevPage.setData({
        state: 1
      })
      wx.navigateBack({
        detail: 1
      })
    } else {
      // wx.navigateTo({
      //   url: '/hyb_yl/onesubpages/pages/shopdetail/shopdetail',
      // })
    }
  },
  onLoad: function(options) {
    var that = this;
    console.log(options.type)
    if (options.type) {
      var type = options.type
      //查询所有药品
      app.util.request({
        'url': 'entry/wxapp/goods.allgoods',
        success: function(res) {
          console.log(res)
          that.setData({
            shop: res.data
          })
        }
      })
      that.setData({
        type: options.type
      })
    }
    var fid = options.fid
    that.setData({
      fid: fid
    })
    this.getAllfenlgoods
    console.log(this.data.proList)
  },
  onReady: function() {
    this.getAllfenlgoods()
  },
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  getAllfenlgoods: function() {
    var that = this
    var fid = that.data.fid
    app.util.request({
      'url': 'entry/wxapp/goods.allfenlgoods',
      data: {
        fid: fid
      },
      success: function(res) {
        console.log(res)
        that.setData({
          proList: res.data,
        })
      }
    })
  }

});